<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 *      [PinTuXiu] (C)2001-2099 ONightjar.com Pintuxiu.com.
 *      This is NOT a freeware, use is subject to license terms
*/

class email_controller extends PZ_Controller{
	public function __construct(){
		parent::__construct();
	}

	public function admintest(){
		$email = $this->param('email');
		$password = $this->param('password');
		$user = load_api('user')->getUserByEmail($email);
		$u2 = load_api('user')->getUserWithGroupByid($user['user_id']);
		if($user&&$user['passwd']==md5($password)&&$u2['system']['usergroup_key']=='admin'){
			$subject = $this->param('subject');
			$to = $this->param('to_email');
			$message = $this->param('message');
			log_message('debug','send subject='.$subject);
			load_api('email')->send($subject,$to,$message);
		}
	}

	public function sendTomem(){
		$type = $this->param('type');
		$uid = $this->param('uid');
		if($type&&$uid){
			log_message('debug',"email_controller sendTomem=$type uid=$uid");
			load_api('email')->sendTomem($type,$uid);
		}
	}

	public function sendToadmin(){
		$site_email = $this->settings['site_email'];
		if($site_email){
			$type = $this->param('type');
			log_message('debug',"email_controller sendToadmin=$site_email type=$type");
			if($type=='report'){
				$this->sid = $this->param('sid');
				$this->link = host_url(site_url('detail/index?shareid='.$this->sid));
				$this->reason = lang($this->param('reason','report_other'),'report');
				$this->nickname = $this->param('nickname');
				$this->subject = lang('subject_report','email');
				log_message('debug','link='.$this->link);
			}
			$message = $this->render('email/'.$type);
			if($message){
				log_message('debug','subject='.$this->subject);
				log_message('debug','message='.$message);
				load_api('email')->send($this->subject,$site_email,$message);
			}
		}
	}
}
